<template>
    <el-dialog
            title="新增考核电价偏差阈值配置"
            :close-on-press-escape="false"
            :show-close="false"
            :close-on-click-modal="false"
            :visible.sync="dialogVisibleStatus"
            width="40%">
            <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="150px" class="demo-ruleForm">
            <el-form-item label="请选择发电类型" prop="type">
                <el-select v-model="ruleForm.type" placeholder="请选择发电类型" style="float:left">
                    <el-option
                            v-for="item in options"
                            :key="item.value"
                            :label="item.label"
                            :value="item.value">
                    </el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="开始时间" required>
                <el-col :span="11">
                    <el-form-item prop="startTime">
                        <el-date-picker type="date" placeholder="选择日期" v-model="ruleForm.startTime"
                                        style="width: 100%;"></el-date-picker>
                    </el-form-item>
                </el-col>
            </el-form-item>
            <el-form-item label="结束时间" required>
                <el-col :span="11">
                    <el-form-item prop="endTime">
                        <el-date-picker type="date" placeholder="选择日期" v-model="ruleForm.endTime"
                                        style="width: 100%;"></el-date-picker>
                    </el-form-item>
                </el-col>
            </el-form-item>
            <el-form-item label="正偏差" prop="plus">
                <el-input v-model="ruleForm.plus" placeholder="请输入正偏差"></el-input>
            </el-form-item>
            <el-form-item label="负偏差" prop="minus">
                <el-input v-model="ruleForm.minus" placeholder="请输入负偏差"></el-input>
            </el-form-item>
            <el-form-item label="备注" prop="remark">
                <el-input v-model="ruleForm.remark" placeholder="请输入备注"></el-input>
            </el-form-item>
            <el-button @click="closeAction">取 消</el-button>
            <el-button type="primary" @click="submitForm('ruleForm')">确 定</el-button>
        </el-form>
    </el-dialog>
</template>

<script>
    export default {
        name: 'ModelView',
        props: ['dialogVisible', 'obj'],

        data() {
            return {
                ruleForm: this.obj || {
                    type: '',
                    startTime: '',
                    endTime: '',
                    plus: '',
                    minus: '',
                    remark:''
                },
                options: [{
                    value: '选项1',
                    label: '发电类型一'
                }, {
                    value: '选项2',
                    label: '发电类型二'
                }, {
                    value: '选项3',
                    label: '发电类型三'
                }],
                rules: {
                    type: [
                        { required: true, message: '请选择发电类型', trigger: 'change'}
                    ],
                    startTime: [
                        {required: true, message: '请选择开始时间', trigger: 'change'}
                    ],
                    endTime: [
                        {required: true, message: '请选择结束时间', trigger: 'change'}
                    ],
                    plus: [
                        {required: true, message: '请输入正偏差', trigger: 'blur'}
                    ],
                    minus: [
                        {required: true, message: '请输入负偏差', trigger: 'blur'}
                    ],
                    remark: [
                        {required: true, message: '请输入备注', trigger: 'blur'}
                    ]
                },

                value:'',
                dialogVisibleStatus: this.dialogVisible,
                objData: this.obj
            };
        },

        mounted: function () {
        },

        methods: {
            submitForm(formName) {
                this.$refs[formName].validate((valid, object) => {
                    if (valid) {
                        console.log(this.ruleForm);
                        this.$emit('closeAction');
                    } else {
                        return false;
                    }
                });
            },

            closeAction() {
                this.$emit('closeAction');
            }
        }
    };
</script>

<style scoped>

</style>